﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FrameWork.Interface;
using Slja.Utility;
using Slja.Model;
using Slja.CC;
using System.Web.UI.HtmlControls;

namespace FrameWork.web.Web.UC
{
    public partial class FileListCtrl : System.Web.UI.UserControl
    {
        FileClass _OrderFileClass;
        OrderExtModel _Order;
        public FileClass OrderFileClass
        {
            get { return _OrderFileClass;}
             set {  _OrderFileClass= value;}
        }
        public OrderExtModel Order
        {
            get { return _Order; }
            set { _Order = value; }
        }
        public EditViewState EditView
        {
            get
            {
                if (ViewState[this.ID + "_EditView"] == null)
                {
                    IOperateView parent = ((object)this.Parent) as IOperateView;
                    if (parent != null)
                    {
                        if (parent.OpRight == FrameWork.Components.OpRightState.Editable
                            || parent.OpRight == FrameWork.Components.OpRightState.Deletable)
                        {
                            ViewState[this.ID + "_EditView"] = EditViewState.UserFreeEdit;
                        }
                        else if (parent.OpRight == FrameWork.Components.OpRightState.Readonly)
                        {
                            ViewState[this.ID + "_EditView"] = EditViewState.OnlyServerLabel;
                        }
                        else if (parent.OpRight == FrameWork.Components.OpRightState.Hidden)
                        {
                            ViewState[this.ID + "_EditView"] = EditViewState.OnlyServerLabel;//不可编辑
                        }
                    }
                    else
                    {
                        ViewState[this.ID + "_EditView"] = EditViewState.UserFreeEdit;
                    }
                }
                return (EditViewState)ViewState[this.ID + "_EditView"];
            }
            set { ViewState[this.ID + "_EditView"] = value; }
        }
        /// <summary>
        /// 加载数据
        /// </summary>
        public void LoadData()
        {
            if (!IsPostBack)
            {
                if (this.EditView == EditViewState.UserFreeEdit
                    || this.EditView == EditViewState.ClientJsEdit)
                {
                    plhAdd.Visible = true;
                }
                else
                {
                    plhAdd.Visible = false;
                }
                plhList.Visible = true;
                bindFileList();
            }
        }      

       protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            HtmlControl lnk = e.Item.FindControl("del") as HtmlControl;
            if (lnk != null)
            {
                if (this.EditView != EditViewState.UserFreeEdit
                    && this.EditView != EditViewState.ClientJsEdit)
                {
                    lnk.Visible = false;
                }
                
            }
        }
        private void bindFileList()
        {
            List<OrderFilesModel> filelist = Order.FileList.FindAll(delegate(OrderFilesModel file) { return file.enum_FileClass == this.OrderFileClass; });
            Repeater1.DataSource = filelist;
            Repeater1.DataBind();
        }
    }
}